From 02cb2ca3845bd9e894977051b994057dcc931c32 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 24 Apr 2010 06:03:17 +0000 Subject: [PATCH] From Warren Toomey: make more fields in NMEA optional on read. --- nmea.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/nmea.c b/nmea.c index 86f11e20a..2f0276f74 100644 --- a/nmea.c +++ b/nmea.c @@ -509,22 +509,37 @@ gprmc_parse(char *ibuf) double speed,course; waypoint *waypt; double microseconds; + char *dmybuf; + int i; if (trk_head == NULL) { trk_head = route_head_alloc(); track_add_head(trk_head); } - sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf,%u", + /* + * Read everything except the dmy, in case lngdeg + * and lngdir are missing. + */ + sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf", &hms, &fix, &latdeg, &latdir, &lngdeg, &lngdir, - &speed, &course, &dmy); + &speed, &course); if (fix != 'A') { /* ignore this fix - it is invalid */ return; } + /* Skip past nine commas in ibuf to reach the dmy value */ + for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) { + dmybuf= strchr(dmybuf, ','); + dmybuf++; + } + + /* Now read dmy from the correct position */ + sscanf(dmybuf,"%u", &dmy); + last_read_time = hms; microseconds = MILLI_TO_MICRO(1000 * (hms - (int)hms)); -- 2.30.2